package com.woniu.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private int code;
    private String message;
    private T data;

    private static <T> Result<T> common(int code,String message,T data){
        return new Result<T>(code,message,data);
    }
    public static <T> Result<T> ok(){
        return common(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),null);
    }
    public static <T> Result<T> ok(T data){
        return common(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),data);
    }
    public static <T> Result<T> ok(int code,String message,T data){
        return common(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(),data);
    }
    public static <T> Result<T> error(int code){
        return common(code,ResultCode.ERROR.getMessage(),null);
    }
    public static <T> Result<T> error(T data){
        return common(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMessage(),data);
    }
    public static <T> Result<T> error(int code,String message){
        return common(code,message,null);
    }
    public static <T> Result<T> error(int code,String message,T data){
        return common(code,message,data);
    }
    public static <T> Result<T> error(){
        return common(ResultCode.ERROR.getCode(),ResultCode.ERROR.getMessage(),null);
    }
}